home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Gamer Resource Kit / Hardcore Gamer Resource Kit - Disc 3.iso / screensavers / saver17.zip / VoodooLights / Sources / cell_tp5.c < prev    next >
C/C++ Source or Header  |  1997-07-23  |  3KB  |  148 lines

  1. /*------------------------------------------------------/
  2. /                                                        /
  3. /    Copyright 1997, SΘrgio Durte <smd@di.fct.unl.pt>    /
  4. /                                                        /
  5. /------------------------------------------------------*/
  6.  
  7.  
  8. #include <stdlib.h>
  9. #include <glide.h>
  10.  
  11. #include "defines.h"
  12. #include "mat.h"
  13. #include "rgb.h"
  14. #include "tex.h"
  15. #include "cam.h"
  16. #include "cell.h"
  17. #include "cell_util.h"
  18. #include "cell_tp1.h"
  19. #include "cell_tp5.h"
  20. #include "cell_tp7.h"
  21.  
  22. static Bool first_init = True ;
  23. static GrMipMapId_t tp5_texture_src ;
  24.  
  25. void tp5_snap_pos_to_dad( Cell *c )
  26. {
  27.     Cell *dad = c->dad ;
  28.     if( dad ) {
  29.         XYZ s ;
  30.         Float l ;
  31.         mat_subv( & c->pos, & (c->dad)->pos, & s ) ;
  32.         l = mat_direction( & s ) ;
  33.         if( l < ZERO ) mat_randomDir( & s ) ;
  34.         mat_combv( min( 2 * c->age, 8.0 ), & s, & dad->pos, & c->pos ) ;
  35.     }
  36. }
  37.  
  38. static void tp5_move_cell( Cell *c )
  39. {
  40.   mat_combv( dt, & c->vel, & c->pos, & c->pos ) ;
  41.   mat_combv( dt, & c->acc, & c->vel, & c->vel ) ;
  42.   
  43.   tp5_snap_pos_to_dad( c ) ;
  44.   cutl_limit_speed( c, c->max_speed ) ;
  45. }
  46.  
  47. static void tp5_acc_cell(Cell *c) 
  48. {
  49.   int n ;
  50.   Cell **p, *dad = c->dad ;
  51.     
  52.   mat_scalev( -0.08, & c->pos, & c->acc ) ;
  53.  
  54.   if( dad ) {
  55.     XYZ d ;
  56.     mat_subv( & dad->pos, & c->pos, & d ) ;
  57.     mat_combv( 100.0 , & d, & c->acc, & c->acc ) ;
  58.   }
  59.  
  60.  
  61.  
  62.   p = cell_get_cells_by_type( CellType1, & n ) ;
  63.   cutl_closest_interaction( c, p, n, 20000.0, 1.0 ) ;
  64.   cutl_closest_interaction( c, p, n, -90000.0, 2.0 ) ;
  65.   
  66.   p = cell_get_cells_by_type( CellType5, & n ) ;
  67.   cutl_closest_interaction( c, p, n, -600000.0, 4.0 ) ;
  68.  
  69. }
  70.  
  71. static void tp5_reproduce_cell( Cell *c) 
  72. {
  73.     
  74.     ctp7_Constructor( c ) ; 
  75.  
  76.     if( c->generation > 4 ) {
  77.         Cell *q = c ;
  78.         while( q->dad ) q = q->dad ;
  79.         q->dad = c ;
  80.     }
  81.     else ctp5_Constructor( c ) ; 
  82.     
  83.     c->reproduce_cell = cell_menopause ;
  84. }
  85.  
  86. void tp5_set_glide_state( void )
  87. {
  88.     if( first_init ) {
  89.         first_init = False ;
  90.         tp5_texture_src = tex_InitTexture("flare2.3df") ;
  91.     }    
  92.     guColorCombineFunction( GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB ) ;
  93.     guAlphaSource( GR_ALPHASOURCE_ITERATED_ALPHA );    
  94.     grAlphaBlendFunction( GR_BLEND_ONE, GR_BLEND_ONE, GR_BLEND_ONE, GR_BLEND_ZERO );
  95.     tex_SetTexSource( tp5_texture_src ) ;
  96. }
  97.  
  98. Cell *ctp5_Constructor( Cell *dad )
  99. {
  100.   Cell *c ;
  101.  
  102.   c = cell_Constructor( CellType5 ) ;
  103.  
  104.   c->dad = dad ;
  105.  
  106.   if( dad ) {
  107.     c->pos.x = dad->pos.x + 1 * ( 1 - 2 * rnd()) ;
  108.     c->pos.y = dad->pos.y + 1 * ( 1 - 2 * rnd()) ;
  109.     c->pos.z = dad->pos.z + 1 * ( 1 - 2 * rnd()) ;
  110.   } 
  111.   else cutl_random_pos( 650.0, c ) ;
  112.  
  113.   if( dad ) {
  114.       c->adulthood = dad->adulthood ;
  115.       c->generation = dad->generation + 1 ;
  116.   }
  117.   else c->adulthood = 5.0 ;
  118.  
  119.  
  120.   c->max_chld = 1 ;
  121.   c->max_speed = 100.0 ;
  122.   c->size = 7.0 ;
  123.  
  124.   c->color.r = 255.0 ;
  125.   c->color.g = 110.0 ;
  126.   c->color.b = 255.0 ;
  127.   c->color.a = 255.0 ;
  128.  
  129.   c->sparkle = 1.0 ;
  130.  
  131.   c->move_cell = tp5_move_cell ;
  132.   c->acc_cell = tp5_acc_cell ;
  133.   c->reproduce_cell = tp5_reproduce_cell ;
  134.  
  135.   return c ;
  136.  
  137. }  
  138.     
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.     
  147.  
  148.